//业务员详情
var app = getApp();
var Api = require("../../../api/method.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    openid:"",
    nickName:"",
    directNickName:"",
    paySource:"",
    directCount:"",
    directAmount:"",
    pageNo:1,
    buyclass:"",
    currentDatas: 0
  },
  //获取当前滑块的index
  // bindchange: function (e) {
  //   this.setData({
  //     currentData: e.detail.current,
  //     pageNo:1
  //   })
  //   this.Course();
  // },
  // //点击切换，滑块index赋值
  // checkCurrent: function (e) {
  //   const that = this;
  //   if (that.data.currentData === e.target.dataset.current) {
  //     return false;
  //   } else {
  //     that.setData({
  //       currentData: e.target.dataset.current
  //     })
  //   }
  // },
  //点击切换滑块
  checkCurrent: function (e) {
    console.log(e.target.dataset.current);
    this.setData({
      currentData: e.target.dataset.current,
      currentDatas: e.target.dataset.current,
      pageNo: 1
    });
    this.Course();
  },
  //业务员详情接口
  Salesmandetail:function(){
    let that = this;
    let list = {
      openId: this.data.openid
    };
    Api.Salesmandetail(list, function (err, res) {
      console.log(res.data);
      if(res.data.code == 1){
        that.setData({
          nickName: res.data.data.nickName,
          directNickName: res.data.data.directNickName,
          paySource: res.data.data.paySource,
          directCount: res.data.data.directCount + res.data.data.indirectCount,
          directAmount: res.data.data.directAmount + res.data.data.indirectAmount 
        })
      }
    });
  },
  //业务员购课列表
  Course:function(e){
    let that = this;
    let list = {
      openId:that.data.openid,
      type: Number(that.data.currentData) + 1,
      pageNo:that.data.pageNo,
      pageSize:10,
    };
    console.log(list);
    Api.Course(list, function (err, res) {
      console.log(res.data);
      if(res.data.code == 1){
        if (that.data.pageNo == 1) {
          that.setData({
            buyclass: res.data.data
          })
        } else {
          that.setData({
            buyclass: that.data.buyclass.concat(res.data.data)
          })
        }
        if (res.data.data == "" && that.data.pageNo != 1) {
          wx.showToast({
            title: "已经到底了",
            icon: "none",
            duration: 1500
          })
        }
        wx.hideLoading();
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      openid: options.openid
    });
    this.Salesmandetail();
    this.Course();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      pageNo: this.data.pageNo + 1
    });
    this.Course();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})